﻿Imports System.Data.SqlClient
Public Class clsCot_SolicitudDetalle
    Private mintIdDetalle As Integer
    Private mintIdSolicitud As Integer
    Private mintIdProducto As Integer
    Private mdblCantidad As Double
    Private mintIdAlmacen As Integer
    Private mintEstado As Integer
    Public Property IdDetalle() As Integer
        Get
            Return mintIdDetalle
        End Get
        Set(ByVal value As Integer)
            mintIdDetalle = value
        End Set
    End Property
    Public Property IdSolicitud() As Integer
        Get
            Return mintIdSolicitud
        End Get
        Set(ByVal value As Integer)
            mintIdSolicitud = value
        End Set
    End Property
    Public Property IdProducto() As Integer
        Get
            Return mintIdProducto
        End Get
        Set(ByVal value As Integer)
            mintIdProducto = value
        End Set
    End Property
    Public Property Cantidad() As Double
        Get
            Return mdblCantidad

        End Get
        Set(ByVal value As Double)
            mdblCantidad = value
        End Set
    End Property
    Public Property IdAlmacen() As Integer
        Get
            Return mintIdAlmacen
        End Get
        Set(ByVal value As Integer)
            mintIdAlmacen = value
        End Set
    End Property
    Public Property Estado() As Integer
        Get
            Return mintEstado
        End Get
        Set(ByVal value As Integer)
            mintEstado = value
        End Set
    End Property

    Public Sub New()
        mintIdDetalle = 0
        mintIdSolicitud = 0
        mintIdProducto = 0
        mdblCantidad = 0
        mintIdAlmacen = 0
        mintEstado = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Cot_SolicitudDetalle (" & _
                            "IdSolicitud," & _
                            "IdProducto," & _
                            "Cantidad," & _
                            "IdAlmacen," & _
                            "Estado)" & _
                            "VALUES (" & _
                            "@IdSolicitud," & _
                            "@IdProducto," & _
                            "@Cantidad," & _
                            "@IdAlmacen," & _
                            "@Estado)" & _
                            " SELECT SCOPE_IDENTITY()"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdSolicitud", mintIdSolicitud)
        Command.Parameters.AddWithValue("IdProducto", mintIdProducto)
        Command.Parameters.AddWithValue("Cantidad", mdblCantidad)
        Command.Parameters.AddWithValue("IdAlmacen", mintIdAlmacen)
        Command.Parameters.AddWithValue("Estado", mintEstado)

        cnConn.Open()
        IdSolicitud = Convert.ToInt32(Command.ExecuteScalar)

        If IdSolicitud > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el producto ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
